package action;

import conexao.FabricaDeConexao;
import dao.JDBCUsuarioDAO;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Usuarios;

public class CadastroUsuario extends HttpServlet {

    private static final long serialVersionUID = 1L;
    JDBCUsuarioDAO JDBCUsuario;
    FabricaDeConexao conecta = new FabricaDeConexao();
    Connection conexao;
    Statement st;
    ResultSet rs;
    String query;

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        String nome = request.getParameter("nome");
        String cpf = request.getParameter("cpf");
        String dataNascimento = request.getParameter("nascimento");
        String telefone = request.getParameter("telefone");
        String email = request.getParameter("email");

        Usuarios novoUsuario = new Usuarios();
        novoUsuario.setNome(nome);
        novoUsuario.setCpf(cpf);
        novoUsuario.setDataNascimento(dataNascimento);
        novoUsuario.setTelefone(telefone);
        novoUsuario.setEmail(email);

        FabricaDeConexao fabrica = new FabricaDeConexao();
        Connection conexao = fabrica.fazConexao();

        JDBCUsuarioDAO bean = new JDBCUsuarioDAO(fabrica, conexao, null, null, query);
        bean.inserirUsuario(novoUsuario);

        System.out.println("DEU CERTO");
        System.out.println("JESUS É A NOSSA FORÇA.");

        response.sendRedirect("http://localhost:8080/ProjetoMarmitaria/faces/sucessoCad.xhtml");

        fabrica.fazConexao();
    }
}
